/**
 * 
 */
package zaphod.toy.ogametool.ui;

import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;

import zaphod.toy.ogametool.ScoutParserUtility;
import zaphod.toy.ogametool.core.model.Colony;

final class IDoubleClickListenerImplementation implements IDoubleClickListener
{
    /**
     * 
     */
    private final ScoutParserMainComposite scoutParserMainComposite;

    /**
     * @param scoutParserMainComposite
     */
    IDoubleClickListenerImplementation(
        ScoutParserMainComposite scoutParserMainComposite )
    {
        this.scoutParserMainComposite = scoutParserMainComposite;
    }

    public void doubleClick( DoubleClickEvent arg0 )
    {
        // TODO Auto-generated method stub
        ISelection selection = arg0.getSelection();
        if ( selection instanceof IStructuredSelection )
        {
            IStructuredSelection newSelectionf = (IStructuredSelection) selection;
            Object object = newSelectionf.getFirstElement();
            if ( object instanceof Colony )
            {
                Colony c = (Colony) object;
                System.out.println( c.getLocation() );
                c.divisor *= 2;
                Clipboard clipBoard = ScoutParserUtility.getInstance()
                    .getClipBoard();

                Object[] data = new Object[]
                { c.getLocation() };
                Transfer[] dataTypes = new Transfer[]
                { TextTransfer.getInstance() };
                clipBoard.setContents( data, dataTypes );

                this.scoutParserMainComposite.tableViewer.refresh();
            }
        }

    }
}